package com.xiangxiangjd.serviceImpl;

import com.xiangxiangjd.controller.helper.$;
import com.xiangxiangjd.bean.ClaimGoods;
import com.xiangxiangjd.mapper.ClaimGoodsMapper;
import com.xiangxiangjd.service.ClaimGoodsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiangxiangjd.bean.result.ResultPage;
import com.xiangxiangjd.controller.model.ApiResultModel;

import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * 申领和物品中间表 服务实现类
 *
 * @author 肖守凯
 * @since 2021-11-08
 */
@Service
public class ClaimGoodsServiceImpl extends ServiceImpl<ClaimGoodsMapper, ClaimGoods>
    implements ClaimGoodsService {
  /**
   * 添加ClaimGoods
   *
   * @param claimGoods 前端传进的参数
   * @return 返回统一信息
   */
  @Override
  public ApiResultModel addClaimGoods(ClaimGoods claimGoods) {
    if (this.save(claimGoods)) {
      return $.success();
    } else {
      return $.error("添加失败");
    }
  }
  /**
   * 编辑跳转页面的回显数据ClaimGoods
   *
   * @param id 前端传进的参数
   * @return 返回实体类
   */
  @Override
  public ClaimGoods selectClaimGoodsByIdClaimGoods(String id) {
    return this.getById(id);
  }

  /**
   * 编辑ClaimGoods
   *
   * @param claimGoods 前端传进的参数
   * @return 返回统一信息
   */
  @Override
  public ApiResultModel editClaimGoods(ClaimGoods claimGoods) {
    if (this.updateById(claimGoods)) {
      return $.success();
    } else {
      return $.error("编辑失败");
    }
  }
  /**
   * 删除一条ClaimGoods
   *
   * @param ids 前端传进的ID
   * @return 返回统一信息
   */
  @Override
  public ApiResultModel delClaimGoodss(List ids) {

    int i = baseMapper.deleteBatchIds(ids);

    return $.success(i);
  }

  /**
   * 分页查询ClaimGoods
   *
   * @param page 页码
   * @param limit 查几条
   * @param claimGoods 前端传进的参数
   * @return 返回统一分页信息
   */
  @Override
  public ResultPage findClaimGoodsByPage(Integer page, Integer limit, ClaimGoods claimGoods) {
    Map<String, Object> paramMap = new HashMap<>();
    page = page == null ? 1 : page;
    limit = limit == null ? 20 : limit;

    paramMap.put("page", (page - 1) * limit);
    paramMap.put("limit", limit);
    paramMap.put("claimGoods", claimGoods);
    List<ClaimGoods> list = baseMapper.selectMyPage(paramMap);
    Integer count = baseMapper.countMyPage(paramMap);
    ResultPage<ClaimGoods> resultPage = new ResultPage<>();
    resultPage.setCode(0);
    resultPage.setCount(count);
    resultPage.setMsg("成功");
    resultPage.setData(list);
    return resultPage;
  }
}
